// https://www.acwing.com/problem/content/845/

#include <iostream>
#include <vector>
#include <cstring>
using namespace std;

int n;
char board[10][10];
int rc[10];
int left_cor[20];
int right_cor[20];

void printBoard() {
    for (int i=0; i<n; i++) {
        for (int j=0; j<n; j++) {
            cout<<board[i][j];
        }
        cout<<endl;
    }
    cout<<endl;
}

void dfs(int row) {
    if (row == n ) {
        printBoard();
        return;
    }

    for (int column=0; column<n; column++) {
        // 计算左下->右上的对角线索引，比如 n 等于 9 时， (2, 1) 的索引是 3，(8, 0) 的索引是 8
        int idx1 = row + column;
        // 计算左上->右下的对角线索引，比如 n 等于 9 时， (2, 1) 的索引是 7，(8, 0) 的索引是 0
        int idx2 = n - column + row - 1;
        if (!rc[column] && !left_cor[idx1] && !right_cor[idx2]) {
            board[row][column] = 'Q';
            rc[column]  = left_cor[idx1] = right_cor[idx2] = 1;
            dfs(row + 1);
            rc[column] = left_cor[idx1] = right_cor[idx2] = 0;
            board[row][column] = '.';
        }
    }

}


int main() {
    scanf("%d", &n);
    memset(board, '.', sizeof(board));
    dfs(0);
    return 0;
}
